﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Collections;
using System.Threading;

namespace ECGServer
{
    class ThreadReceiveData
    {
        private IPEndPoint workStationEndPoint;
        byte[] data;
        private Thread thread;

        public ThreadReceiveData()
        {            
        }

        public void run()
        {
            thread = new Thread(new ThreadStart(receiveData));
            thread.Start();
        }

        public void receiveData()
        {
            while (true)
            {
                try
                {
                    data = ECGServer.ServerUDPSocket.Receive(ref workStationEndPoint);

                    //Instantiate a new threadHandleData and queue it into ThreadPool
                    ThreadHandleData thread = new ThreadHandleData(data, workStationEndPoint);
                    ThreadPool.QueueUserWorkItem(thread.handleData);
                }
                catch (Exception e)
                {
                }
            }
        }

        public Thread Thread
        {
            get { return thread; }
        }
    }
}
